<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

date_default_timezone_set('Europe/Warsaw');
$address = 'adam.pioterek+website@protonmail.ch';
$subject = date(DATE_ATOM);

$json = file_get_contents('php://input');
$data = json_decode($json, true);

if (!isset($data['email'])) {
    http_response_code(400);
    echo 'msg not given';
    die();
}

$msg = $data['email'];
if (preg_match("@^-----BEGIN PGP MESSAGE-----[\r\n]+Version: OpenPGP.js v3.0.11[\r\n]+Comment: https://openpgpjs.org[A-Za-z0-9+/=\r\n]+-----END PGP MESSAGE-----[\r\n]*$@", $msg) !== 1) {
    http_response_code(400);
    echo 'not encrypted';
    die();
}
$msg = wordwrap($msg, 70, " \r\n");

mail($address, $subject, $msg);

?>
